package com.itheima.controller;

import com.itheima.dto.AdminChannelDto;
import com.itheima.dto.AdminDto;
import com.itheima.service.ChannelService;
import com.itheima.vo.AdminChannelVo;
import com.itheima.vo.PagingQueryVo;
import com.itheima.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author :wujunjie
 * createTime :2023-01-04 15:15
 * description :
 */
@RestController
@RequestMapping("/api/v1/channel")
public class ChannelController {
    @Autowired
    private ChannelService channelService;

    @PostMapping("/save")
    public Result saveChannel(@RequestBody AdminChannelDto dto){
        Boolean save=channelService.saveChannel(dto);
        if (save){
            return Result.success();
        }
        return Result.error();
    }

    @GetMapping("/del/{id}")
    public Result deleteChannel(@PathVariable Long id){
        Boolean del=channelService.deleteChannel(id);
        if (del){
            return Result.success();
        }
        return Result.error();
    }

    @PostMapping("/update")
    public Result updateChannel(@RequestBody AdminChannelDto dto){
        Boolean update=channelService.updateChannel(dto);
        if (update){
            return Result.success();
        }
        return Result.error();
    }

    @PostMapping("/list")
    public Result selectPage(@RequestBody AdminChannelDto dto){
        PagingQueryVo<AdminChannelVo> vo=channelService.selectPage(dto);
        return Result.adminChannelSuccess(vo);
    }

}
